﻿<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Skeleton.Master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
    <!-- Primary Page Layout
  –––––––––––––––––––––––––––––––––––––––––––––––––– -->
    <%--<header>
        <span><h4 style="margin:4px;">SiteView</h4></span>
        <hr style="margin:0;border-bottom:3px;" />
    </header>--%>

    <div class="container">
        <form runat="server" action="" method="post" id="request_form">
            <input type="hidden" name="action" id="frm_action" value="change" />
            <input type="hidden" name="fdname" id="frm_fdname" />
            <input type="hidden" name="fdtype" id="frm_fdtype" />

            <div class="row">
                <div class="twelve columns">
                    <h4>SiteView</h4>
                    <div>
                        <%
                            foreach (var logicalDrive in System.IO.Directory.GetLogicalDrives())
                            {
                                Response.Write(string.Format("<button class=\"button-primary\">{0}</button>&nbsp;", logicalDrive));
                            }
                        %>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="twelve columns">
                    <label for="current_path">Path</label>
                    <input type="text" id="current_path" name="current_path" class="u-full-width" value="<%:Current_Path %>" />
                    
                </div>
            </div>
        </form>

        <table class="u-full-width">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Type</th>
                    
                </tr>
            </thead>
            <tbody>

                <%
                    if (System.IO.Directory.GetParent(Current_Path) != null)
                    {
                %>
                <tr>
                    <td>
                        <span class="link_button" onclick="pick('<%:Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(System.IO.Directory.GetParent(Current_Path).FullName))%>', 'directory')"><%: System.IO.Directory.GetParent(Current_Path).Name %></span>
                    </td>
                    <td>Directory</td>
                </tr>      
                <%  
                    }
                %>

                <%
                foreach (var dir in System.IO.Directory.GetDirectories(Current_Path))
                {
                %>
                <tr>
                    <td>
                        <span class="link_button directory" onclick="pick('<%:Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(dir.Trim()))%>', 'directory')"><%: dir %></span>
                    </td>
                    <td>Directory</td>
                </tr>
                <%
                }
                %>

                <%
                foreach (var file in System.IO.Directory.GetFiles(Current_Path))
                {
                %>
                <tr>
                    <td>
                        <span class="link_button file" onclick="download('<%:Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(file.Trim()))%>', 'file')"><%: file %></span>
                    </td>
                    <td>File</td>
                </tr>
                <%
                }
                %>

            </tbody>
        </table>
    </div>
</asp:Content>


<asp:Content runat="server" ID="CustomPageScript" ContentPlaceHolderID="ScriptContent">
<script type="text/javascript">
    function pick(fdname, fdtype) {
        $("#request_form #frm_action").val("update");
        $("#request_form #frm_fdname").val(fdname);
        $("#request_form #frm_fdtype").val(fdtype);
        $("#request_form").submit();
    }
    function download(fdname, fdtype) {
        $("#request_form #frm_action").val("download");
        $("#request_form #frm_fdname").val(fdname);
        $("#request_form #frm_fdtype").val(fdtype);
        $("#request_form").submit();
    }
    (function ($) {
        $(document).ready(function () {
        });
    }(jQuery));
</script>
</asp:Content>